package com.java110.mall.goods.bmo.housekeepingResource.impl;

import com.java110.core.annotation.Java110Transactional;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.mall.goods.bmo.housekeepingResource.ISaveHousekeepingResourceBMO;
import com.java110.intf.cart.IHousekeepingFeeConfigInnerServiceSMO;
import com.java110.intf.cart.IHousekeepingResourceFeeInnerServiceSMO;
import com.java110.intf.goods.IHousekeepingResourceInnerServiceSMO;
import com.java110.po.housekeeping.HousekeepingFeeConfigPo;
import com.java110.po.housekeeping.HousekeepingResourcePo;
import com.java110.po.housekeeping.HousekeepingResourceFeePo;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service("saveHousekeepingResourceBMOImpl")
public class SaveHousekeepingResourceBMOImpl implements ISaveHousekeepingResourceBMO {

    @Autowired
    private IHousekeepingResourceInnerServiceSMO housekeepingResourceInnerServiceSMOImpl;
    @Autowired
    private IHousekeepingFeeConfigInnerServiceSMO housekeepingFeeConfigInnerServiceSMOImpl;
    @Autowired
    private IHousekeepingResourceFeeInnerServiceSMO housekeepingResourceFeeInnerServiceSMOImpl;
    /**
     * 添加小区信息
     *
     * @param housekeepingResourcePo
     * @return 订单服务能够接受的报文
     */
    @Java110Transactional
    public ResponseEntity<String> save(HousekeepingResourcePo housekeepingResourcePo, HousekeepingFeeConfigPo housekeepingFeeConfigPo, HousekeepingResourceFeePo housekeepingResourceFeePo) {

        //保存物品
        housekeepingResourcePo.setResId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_resId));
        int flag = housekeepingResourceInnerServiceSMOImpl.saveHousekeepingResource(housekeepingResourcePo);

        if (flag < 1) {
        return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "保存失败");
        }

        //保存物品默认费用
        housekeepingFeeConfigPo.setConfigId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_configId));
        int fclag = housekeepingFeeConfigInnerServiceSMOImpl.saveHousekeepingFeeConfig(housekeepingFeeConfigPo);
        if (fclag < 1) {
            return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "保存失败");
        }

        //保存物品与费用明细关系
        housekeepingResourceFeePo.setResFeeId(GenerateCodeFactory.getGeneratorId("15"));
        housekeepingResourceFeePo.setResId(housekeepingResourcePo.getResId());
        housekeepingResourceFeePo.setResName(housekeepingResourcePo.getResName());
        housekeepingResourceFeePo.setConfigId(housekeepingFeeConfigPo.getConfigId());
        housekeepingResourceFeePo.setFeeName(housekeepingFeeConfigPo.getFeeName());
        housekeepingResourceFeePo.setShopId(housekeepingResourcePo.getShopId());
        int rflag = housekeepingResourceFeeInnerServiceSMOImpl.saveHousekeepingResourceFee(housekeepingResourceFeePo);
        if (rflag < 1) {
            return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "保存失败");
        }

        return ResultVo.createResponseEntity(ResultVo.CODE_OK, "保存成功");
    }

}
